package com.jerei.store.controller;

import com.jerei.store.entity.Order;
import com.jerei.store.entity.OrderItem;
import com.jerei.store.service.IOrderItemService;
import com.jerei.store.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/orderItem")
public class OrderItemController extends BaseController {

    @Autowired
    private IOrderItemService orderItemService;

    @RequestMapping("/add")
    public JsonResult<Void> addOrder(Integer oid, Integer[] arr, HttpSession session){

        String username=getUsernameFromSession(session);
        System.out.println("创建item时的 cid arr="+ Arrays.toString(arr));
        System.out.println("创建item时的oid="+oid);
        orderItemService.insertOrder(oid,arr,username);
        return new JsonResult<>(OK);
    }


    @RequestMapping("/show")
    public JsonResult<List<Order>> showOid(HttpSession session){
        Integer uid=getUidFromSession(session);
        List<Order> lists=orderItemService.findByOid(uid);
        System.out.println(lists);
        return new JsonResult<>(OK,lists);

    }

}
